﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>消息</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" type="text/css" href="/Styles/demo.css" />
    <script src="/scripts/boot.js" type="text/javascript"></script>
</head>
<body>
    <div class="mini-fit" >
        
        <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" 
            url="/Home/GetAllPosts"  idField="Id"
            sizeList="[5,10,20,50]" pageSize="20" onrowclick="rowclick" showPager="false">
            <div property="columns">
                <div type="indexcolumn" ></div>
                <div name="sstatus" width="20" align="center" headerAlign="center" renderer="onStatusRenderer">状态</div>    
                <div field="Title" width="120" headerAlign="center">标题</div>    
                <div field="PostTime" headerAlign="center" dateformat="yyyy-MM-dd HH:mm:ss" width="120px">时间</div> 
                <div field="PostUser" headerAlign="center">发布者</div> 
            </div>
        </div> 

    </div>
    <script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
        grid.load();
        function rowclick(sender, record) {
            //alert(sender.record.Title);
            mini.showMessageBox({
                width: 450,
                title: sender.record.Title,
                buttons: ["ok"],
                html: sender.record.PostContent.replace(/\n/g, '<br/>').replace(/[ ]/g, "&nbsp;"),
                showModal: false,
                callback: function (action) {
                    $.ajax({
                        url: "/Home/PostReaded/" + sender.record.Id,
                        dataType: "json",
                        success: function () {
                            location.href = location.href;
                        },
                        error: function () {
                        }
                    });
                }
            });
        }
        function editRow(id) {
            //alert(id);
        }
        function onActionRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record.Id;
            var rowIndex = e.rowIndex;

            var s = ' <a class="Edit_Button" href="javascript:editRow(\'' + uid + '\')" >编辑</a>'
                + ' <a class="Delete_Button" href="javascript:if(confirm(\'确定要删除这条记录吗？\')){deleteItem(\'' + uid + '\')}">删除</a>';
            return s;
        }
        function onStatusRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            if (record.Readed == true) {
                return "<img src='/Styles/email_open.png' alt='已读'/>已读"
            }
            else {
                return "<img src='/Styles/email_go.png' alt='未读'/>未读"
            }
        }
    </script>
</body>
</html>
